<template>
  <div class="m-container">
    <el-table :data="tasks" style="width: 100%">
      <el-table-column prop="id" label="编号" width="50"></el-table-column>
      <el-table-column prop="name" label="名称" width="180"></el-table-column>
      <el-table-column prop="taskType" label="类型" width="80"></el-table-column>
      <el-table-column width="180" label="状态">
        <template #default="scope">
          {{scope.row.stateName}}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
      <el-table-column fixed="right" label="操作">
        <template #default="scope">
          <el-button type="text" size="small" @click="viewTask(scope.row.id)" :disabled="scope.row.state<=0">员工绩效</el-button>
          <!-- <el-button type="text" size="small" @click="cadreTask(scope.row.id)" :disabled="scope.row.state<=0">干部绩效</el-button> -->
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script lang="ts">
import {defineComponent} from 'vue'
import {getTaskAll} from '@/api/salary'
import {useRouter} from 'vue-router'
import { getRoles } from '@/utils/store'
import { ElMessage } from 'element-plus'
export default defineComponent({
  setup(props){
    let router = useRouter()
    return {
      router
    }
  },
  name:'Merit',
  data() {
    return {
      tasks: []
    }
  },
  mounted() {
    this.getTasks()
  },
  methods: {
    // 获取任务列表
    getTasks() {
      getTaskAll().then(res => {
        this.tasks = res.data
      })
    },    
    // 计算状态
    stateType(st: number) {
      switch(st){
        case -1: return {type: 'danger', txt: '锁定'}
        case 1: return {type: 'primary', txt: '发布中'}
        case 2: return {type: 'success', txt: '已完成'}
        default: return {type: 'info', txt: '未发布'}
      }
    },
    // 查看任务
    viewTask(id: string) {
      this.router.push(`/task/merit/task/${id}`)
    },
    // 设置干部绩效工资
    cadreTask(id: string) {
      const roles = getRoles()
      if(roles.some(role=>role==='admin')) {
        this.router.push(`/task/cadre/task/${id}`)
      }
      else{
        ElMessage.error('对不起，您没有权限!')
      }
    }
  }
})
</script>
<style scoped>
</style>
